package com.doudou.commons.utils;

import java.util.Random;

/**
 * @Author: 傻男人
 * @Date: 2020/5/21 16:37
 * @Version: 1.0
 * @Description: 生成随机数
 */
public class RandomUtils {

    private static Random random = new Random();

    /**
     * 随机生成一个数字或者字母
     * @return
     */
    public static String getOneRandom(){
        if (random.nextInt(2) % 2 == 0) {
            int choice = random.nextInt(2) % 2 == 0 ? 65 : 97;
            return String.valueOf((char) (choice + random.nextInt(26)));
        }else {
            return String.valueOf(random.nextInt(10));
        }
    }

    /**
     * 生成指定长度的数字
     * @return
     */
    public static String getNumBerRandom(int len){
        if(len <= 0){
            return null;
        }
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < len; i++) {
            result.append(random.nextInt(10));
        }
        return result.toString();
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10 ; i++) {
            System.out.println(getNumBerRandom(4));
        }
    }

}
